/*=============================================================================
#    The element-comm is a tentative program used to test our ideas.           
#                       Copyright (C)  bgao                                    
#
#     This program is free software; you can redistribute it and/or            
#      modify it under the terms of the GNU General Public License             
#     as published by the Free Software Foundation; either version 2           
#         of the License, or (at your option) any later version.               
#
#     This program is distributed in the hope that it will be useful,          
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
#             GNU General Public License for more details.                    
#
#    You should have received a copy of the GNU General Public License        
#     along with this program; if not, write to the Free Software             
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
#                       MA  02110-1301, USA.                                  
#==============================================================================
# $Id$ 
#
# $Author$ 
#
# $Revision$ 
#
# $Date$ 
#
# Description: 
#
=============================================================================*/
#include "rtos-wsn.h"
#include "wsn-blink-bind.h"


static uint16 blink_pattern = 0;



void CONTROL_IN_TOGGLE(on)(uint16 pattern)//CONTROL_BLINK_TOGGLEon
{
	uint8 i = 0;
	while(i < SWITCH_NUM)
	{
		if ((pattern >> i)  & 0x01)
			switch(i){
			case 0:
				blink_pattern |= LED_YELLOW;
				ON_LED_YELLOW;	// YELLOW LED ON
				break;		
			case 1:
				blink_pattern |= LED_GREEN;
				ON_LED_GREEN;	// GREEN LED ON
				break;
			case 2:
				blink_pattern |= LED_RED;
				ON_LED_RED;		// RED LED ON
				break;
			default:
				return;
			}
		i++;
	}// end while
	
}


void CONTROL_IN_TOGGLE(off)(uint16 pattern)//CONTROL_BLINK_TOGGLEoff
{
	uint8 i = 0;
	while(i < SWITCH_NUM)
	{
		if ((pattern >> i)  & 0x01)
			switch(i){
			case 0:
				blink_pattern &= ~LED_YELLOW;
				OFF_LED_YELLOW; // YELLOW LED OFF
				break;		
			case 1:
				blink_pattern &= ~LED_GREEN;
				OFF_LED_GREEN;// GREEN LED OFF
				break;
			case 2:
				blink_pattern &= ~LED_RED;
				OFF_LED_RED;//RED LED OFF
				break;
			default:
				return;
			}
		i++;
	}// end while
	
}

void CONTROL_IN_TOGGLE(set)(uint16 pattern)//CONTROL_BLINK_TOGGLEset
{
	uint8 i = 0;
	while(i < SWITCH_NUM)
	{
		i++;
		switch(i){
		case 1:
			if(pattern & 0x01){
				blink_pattern |= LED_YELLOW;
				ON_LED_YELLOW; 
			}else{
				blink_pattern &= ~LED_YELLOW;
				OFF_LED_YELLOW;
			}
			break;		
		case 2:
			if(pattern & 0x02){
				blink_pattern |= LED_GREEN;
				ON_LED_GREEN; 
			}else{
				blink_pattern &= ~LED_GREEN;
				OFF_LED_GREEN;
			}
			break;	
		case 3:
			if(pattern & 0x04){
				blink_pattern |= LED_RED;
				ON_LED_RED; 
			}else{
				blink_pattern &= ~LED_RED;
				OFF_LED_RED;
			}
			break;	
		default:
			return;
		}
	}// end while
}

uint16 CONTROL_IN_TOGGLE(get)(void)//CONTROL_BLINK_TOGGLEget
{
	return blink_pattern;
}
